<template>
  <div class="table-page-search-wrapper ccslh">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item :label="$t('key.xh')">
              <a-input v-model="queryParam.xh" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item :label="$t('key.name')">
              <a-input v-model="queryParam.xm" placeholder=""/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="12">
              <a-form-item :label="$t('key.moveType')">
                <a-select v-model="queryParam.ydlx" allowClear>
                  <a-select-option v-for="i in TYPE0070" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item :label="$t('key.yx')">
                <a-select v-model="queryParam.ssyxm" allowClear showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item :label="$t('key.nj')">
                <a-select v-model="queryParam.sznj" allowClear>
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="8" :sm="16">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)">{{ $t('button.query') }}</a-button>
              <a-button style="margin-left: 8px" @click="resetForm">{{ $t('button.reset') }}</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? $t('button.packUp') : $t('button.advance') }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        v-if="initDone"
        class="abnormal-table"
        ref="table"
        size="default"
        rowKey="xsxxId"
        :columns="columns"
        :data="loadData"
        :alert="{show: false}"
        :pageSize="parameter.pageSize"
        :pageNum="parameter.pageNum"
        :scroll="{x:1500}"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>

        <a-tooltip slot="ydsm" slot-scope="a" placement="topLeft">
          <template slot="title">
            {{ a }}
          </template>
          {{ a }}
        </a-tooltip>
        <a v-if="record.ydly === '2'" slot="ydtp" slot-scope="ydtp, record" @click="showAttach(ydtp)">查看附件</a>
        <a slot="operation" slot-scope="a, b" @click="exportCheckForm(b)">导出审批报表</a>
      </s-table>
    </a-card>

    <attach-modal 
      :visible="attachVisible" 
      @cancel="attachVisible = false" 
      :imgs="ydtp"/>
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import searchMixin from '@/utils/searchRemain'
import attachModal from './attachModal'

export default {
  mixins: [ searchMixin ],
  components: {
    STable,
    attachModal
    // transferForm
  },
  data () {
    return {
      // 高级搜索 展开/关闭
      advanced: true,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: this.$t('key.no'),
          width: '60px',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: this.$t('key.xh'),
          width: '150px',
          dataIndex: 'xh'
        },
        {
          title: this.$t('key.name'),
          dataIndex: 'yxm'
        },
        {
          title: this.$t('key.yx'),
          dataIndex: 'yyxsmc'
        },
        {
          title: this.$t('key.nj'),
          dataIndex: 'ynj'
        },
        {
          title: this.$t('key.moveDate'),
          dataIndex: 'ydrq'
        },
        // {
        //   title: this.$t('key.applyTime'),
        //   dataIndex: 'createDate'
        // },
        {
          title: this.$t('key.moveType'),
          dataIndex: 'ydlbmc'
        },
        {
          title: this.$t('key.moveReason'),
          dataIndex: 'ydyymc'
        },
        {
          title: this.$t('key.moveWhat'),
          width: '300px',
          dataIndex: 'ydsm',
          scopedSlots: { customRender: 'ydsm' }
        },
        {
          title: this.$t('key.reviewStatus'),
          dataIndex: 'shztmc'
        },
        {
          title: this.$t('key.attachment'),
          dataIndex: 'ydtp',
          scopedSlots: { customRender: 'ydtp' },
        },
        // {
        //   title: this.$t('key.auditIntro'),
        //   dataIndex: 'shsm'
        // },
        {
          title: this.$t('key.option'),
          dataIndex: 'operation',
          fixed: 'right',
          width: '120px',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.student.transferingCheckList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {},
      initDone: false,
      visible: false,
      form: this.$form.createForm(this),
      checkId: '',
      attachVisible: false,
      ydtp: [],
    }
  },
  computed: {
    ...mapState({
      TYPE0070: state => state.app['TYPE0070'], // 异动类型
      TYPE0075: state => state.app['TYPE0075'], // 学生类别
      TYPE0126: state => state.app['TYPE0126'], // 年级
      lang: state => state.account.lang
    })
  },
  created () {
    // this.initSelectMenu()
    this.$store.dispatch('app/setDictionary', 'TYPE0070')
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
  },
  methods: {
    filterOption (value, yx) {
      return yx.componentOptions.children[0].text.indexOf(value) !== -1
    },
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
        this.initDone = true
      })
    },
    resetForm () {
      this.queryParam = {}
      this.selectMenu.zy = []
    },
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zy', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zy', [])
      }
    },
    checkTransfer (item) {
      this.$router.push(`/stuStatus/stuView?xh=${item.xh}`)
      // this.$emit('toInfo', true)
    },
    refreshTable () {
      this.$refs.table.refresh(true)
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    showChecked (b) {
      this.form.resetFields()
      this.checkId = b.id
      this.visible = true
    },
    confirm () {
      this.form.validateFields((err, values) => {
        if (err) return
        this.$api.student.transferingCheck({...values, xjydId: this.checkId}).then(res => {
          this.$message.success(res.msg)
          this.visible = false
          this.$refs.table.refresh(false)
        })
      })
    },
    showAttach (ydtp) {
      this.attachVisible = true
      this.ydtp = ydtp.split(',')
    },
    exportCheckForm(b) {
      this.$export(`teacherClient/xjydPrint?id=${b.id}`)
    }
  }
}
</script>

<style lang="less">
.ccslh{
  .abnormal-table{
    table {
      table-layout:fixed;
    }
    tr td:nth-child(9){
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

</style>